home *** CD-ROM | disk | FTP | other *** search
- ;-------------------------fix routine begins--------------------------+
- ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
- ; page : 107
- ;
- ; NAME FIX
- ;
- ; ROUTINE FOR Conversion from Internal Floating Point to 16-Bit Integer
- ;
- ; FUNCTION: This routine converts from internal single precision binary
- ; floating point to internal 16-bit signed two's complement integer.
- ;
- ; INPUT: Upon entry a single precision binary floating point is in
- ; SFPBUFF. The single precision floating point nu ber has a 24-bit
- ; binary mantissa, a sign bit, and an 8-bit exponent biased by 128.
- ;
- ; OUTPUT: Upon exit a 16-bit signed two's complement binary number
- ; is in the DX register.
- ;
- ; REGISTERS USED: Only DX is modified, used for output.
- ;
- ; SEGMENTS REFERENCED: The data segment contains storage for SFPBUFF.
- ;
- ; ROUTINES CALLED: None
- ;
- ; SPECIAL NOTES: Equates used to shorten address fields.
- ;
- ; ROUTINE TO CONVERT FROM INTERNAL FLOATING POINT TO INTERNAL INTEGER
- ; (truncate).
- ;
- fix proc far
- ;
- ; the number is in sfpbuff
- ;
- push cx ; save registers
- push ax
- ;
- ; get the mantissa
- mov ax,sfpbuffw0 ; AX gets the low part
- mov dx,sfpbuffw2 ; DX gets high part
- and dx,007Fh ; just the mantissa
- or dx,0080h ; restore MSB
- ;
- ; get the exponent
- mov cl,sfpbuffb3 ; get the exponent
- mov ch,0 ; extend to 16-bit
- sub cx,88h ; subtract bias
- cmp cx,0 ; check its sign
- jl fix1 ; if negative
- jg fix2 ; if positive
- je fix3 ; if zero
- ;
- fix1:
- ; shift right
- neg cx ; absolute value
- ;
- fix2:
- sar dx,1 ; shift all bits right
- rcr ax,1 ; carry on
- loop fix2
- ;
- jmp fix4 ; end of case
- ;
- fix3:
- ; shift left
- sal ax,1 ; shift all bits left
- rcl dx,1 ; carry on
- loop fix3
- ;
- jmp fix4 ; end of case
- ;
- fix4:
- ; check the sign
- mov al,sfpbuffb2 ; get sign
- and al,80h ; just bit 7
- jz fix5 ; is it on ?
- neg dx ; two's compl if negative
- ;
- fix5:
- ;
- pop ax ; restore registers
- pop cx
- ret ; return
- ;
- fix endp
- ;-------------------------fix routine ends---------------------------+